"use strict";
const { Model, DataTypes } = require("sequelize");
const { IdGenerator } = require("../utils/idGenerator");
module.exports = (sequelize, DataTypes) => {
  class Menu extends Model {
    /**
     * Helper method for defining associations.
     * This method is not a part of Sequelize lifecycle.
     * The `models/index` file will call this method automatically.
     */
    static associate(models) {
      // define association here
    }
  }

  Menu.init(
    {
      id: {
        type: DataTypes.INTEGER, // 无符号整数类型
        allowNull: false,
        primaryKey: true,
        defaultValue: function () {
          return IdGenerator.getNextID(); // 使用封装的ID生成方法
        },
      },
      menuType: {
        type: DataTypes.INTEGER,
        defaultValue: 0,
      },
      higherMenuOptions: DataTypes.STRING,
      parentId: DataTypes.STRING,
      title: DataTypes.STRING,
      name: DataTypes.STRING,
      path: DataTypes.STRING,
      component: DataTypes.STRING,
      rank: {
        type: DataTypes.INTEGER,
        defaultValue: 0,
      },
      redirect: DataTypes.STRING,
      icon: DataTypes.STRING,
      extraIcon: DataTypes.STRING,
      enterTransition: DataTypes.STRING,
      leaveTransition: DataTypes.STRING,
      activePath: DataTypes.STRING,
      auths: DataTypes.STRING,
      frameSrc: DataTypes.STRING,
      frameLoading: {
        type: DataTypes.BOOLEAN,
        defaultValue: false,
      },
      keepAlive: {
        type: DataTypes.BOOLEAN,
        defaultValue: false,
      },
      hiddenTag: {
        type: DataTypes.BOOLEAN,
        defaultValue: false,
      },
      fixedTag: {
        type: DataTypes.BOOLEAN,
        defaultValue: false,
      },
      showLink: {
        type: DataTypes.BOOLEAN,
        defaultValue: false,
      },
      showParent: {
        type: DataTypes.BOOLEAN,
        defaultValue: false,
      },
    },
    {
      sequelize,
      modelName: "Menu",
    },
  );
  return Menu;
};
